package Reeks5.VanRansbeeck.Kevin.View;

import Reeks5.VanRansbeeck.Kevin.Model.Kaart;
import Reeks5.VanRansbeeck.Kevin.Util.Settings;
import java.awt.Dimension;
import java.awt.Rectangle;
import java.net.URL;
import javax.swing.*;

public class KaartDrawTile extends JPanel  {
    //Spel spel;
    Kaart k;
    JLabel kaart;
    JLabel string;
    URL imageLoc;
    
    public KaartDrawTile() {
        this(null);
    }
    public KaartDrawTile(Kaart k) {
        super();
        
        Box b1;
        
        b1 = Box.createVerticalBox();
        
        if(k == null) {
            imageLoc = ClassLoader.getSystemResource(Settings.cd.getDeckURL());
            string = new JLabel("***");
        } else {
            this.setK(k);
            imageLoc = ClassLoader.getSystemResource(Settings.cd.getImageURL(this.getK()));
            string = new JLabel(this.getK().toString());
        }
        
        kaart = new JLabel(new ImageIcon(imageLoc));
        
        b1.add(kaart);
        b1.add(string);
        
        this.add(b1);
    }

    public Kaart getK() {
        return k;
    }

    public void setK(Kaart k) {
        this.k = k;
    }
    
    public void redraw () {
        Rectangle r = kaart.getBounds();
        kaart.setIcon(new ImageIcon(ClassLoader.getSystemResource(Settings.cd.getImageURL(this.getK()))));
        string.setText(this.getK().toString());
        kaart.repaint(); string.repaint();
        kaart.setBounds(r);
    }

}
